package com.seller.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import com.seller.util.BaseUtil;
import com.seller.vo.Seller;

@Aspect
@Component
public class SellerPsdAspect {
	
	private final String registPC = "execution(* com.seller.service.SellerManager.registSeller(..))";
	private final String loginPC = "execution(* com.seller.service.SellerManager.loginSeller(..))";
	private final String loginPC2 = "execution(* com.seller.service.SellerManager.loginSeller2(..))";
	//private final String resetpwdPC = "execution(* com.seller.service.SellerManager.sellerreset(..))";
	
	@Around(registPC)
	public Object registMdProcess(ProceedingJoinPoint jp){
		Object o=null;
		Seller s=(Seller)jp.getArgs()[0];
		s.setSellerPsd((BaseUtil.JohnMd(s.getSellerPsd(), "md5")));
		try {
			o=jp.proceed();
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return o;
	}
	@Around(loginPC)
	public Object loginMdProcess(ProceedingJoinPoint jp){
		Object o=null;
		String psd=(String)jp.getArgs()[1];
		try {
			o=jp.proceed(new Object[]{jp.getArgs()[0],BaseUtil.JohnMd(psd, "md5")});
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return o;
	}
	@Around(loginPC2)
	public Object loginMdProcess2(ProceedingJoinPoint jp){
		Object o=null;
		Seller seller = (Seller) jp.getArgs()[0];
		String psd=seller.getSellerPsd();
		seller.setSellerPsd(BaseUtil.JohnMd(psd, "md5"));
		try {
			o=jp.proceed();
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return o;
	}

}
